const Router = require('koa-router')
const discussService = require('../services/discuss')
const router = new Router({prefix:'/api/chat'})

// const middle = ctx => {
//     ctx.response.body = ''
// }

router.get('/view',async(ctx)=>{
    const list = await discussService.showDiscuss()
    ctx.body = {list:list,code:200}
})

router.post('/send',async(ctx)=>{
    const {username,content} = ctx.request.body
    if(!username || !content){
        throw new Error('名字或内容不能为空')
    }
    // if(content.length>140){
    //     throw new Error('内容不能超过140个字')
    // }
    console.log(username,content)
    await discussService.sendDiscuss(username,content)
    // ctx.send({res:200})
    ctx.body = {code:200}
})

module.exports = router